package com.industrial.app.controller.formal;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.industrial.app.domain.formal.BizPmiFormal;
import com.industrial.app.service.IBizPmiFormalService;
import com.industrial.common.core.utils.poi.ExcelUtil;
import com.industrial.common.core.web.controller.BaseController;
import com.industrial.common.core.web.domain.AjaxResult;
import com.industrial.common.core.web.page.TableDataInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 山东制造业PMIController
 * 
 * @author Zhou_S
 * @date 2024-01-02
 */
@RestController
@RequestMapping("/biz/formal/pmi")
public class BizPmiFormalController extends BaseController
{
    @Autowired
    private IBizPmiFormalService bizPmiFormalService;

    /**
     * 查询山东制造业PMI列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BizPmiFormal bizPmiFormal)
    {
        if(StringUtils.isNotBlank(bizPmiFormal.getDates())){
        DateTime datesTimes= DateUtil.parse(bizPmiFormal.getDates(),"yyyy年MM月");
        bizPmiFormal.setDates(DateUtil.format(datesTimes,"yyyy-MM"));
    }else{
        throw new RuntimeException("未指定日期！");
    }
        startPage();
        List<BizPmiFormal> list = bizPmiFormalService.selectBizPmiFormalList(bizPmiFormal);
        return getDataTable(list);
    }

    /**
     * 导出山东制造业PMI列表
     */
//    @PreAuthorize("@ss.hasPermi('pimFormal:pimFormal:export')")
//    @Log(title = "山东制造业PMI", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizPmiFormal bizPmiFormal)
    {
        List<BizPmiFormal> list = bizPmiFormalService.selectBizPmiFormalList(bizPmiFormal);
        ExcelUtil<BizPmiFormal> util = new ExcelUtil<BizPmiFormal>(BizPmiFormal.class);
        util.exportExcel(response, list, "山东制造业PMI数据");
    }

    /**
     * 获取山东制造业PMI详细信息
     */
//    @PreAuthorize("@ss.hasPermi('pimFormal:pimFormal:query')")
    @GetMapping(value = "/{baseId}")
    public AjaxResult getInfo(@PathVariable("baseId") String baseId)
    {
        return success(bizPmiFormalService.selectBizPmiFormalByBaseId(baseId));
    }

    /**
     * 新增山东制造业PMI
     */
//    @PreAuthorize("@ss.hasPermi('pimFormal:pimFormal:add')")
//    @Log(title = "山东制造业PMI", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizPmiFormal bizPmiFormal)
    {
        return toAjax(bizPmiFormalService.insertBizPmiFormal(bizPmiFormal));
    }

    /**
     * 修改山东制造业PMI
     */
//    @PreAuthorize("@ss.hasPermi('pimFormal:pimFormal:edit')")
//    @Log(title = "山东制造业PMI", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizPmiFormal bizPmiFormal)
    {
        return toAjax(bizPmiFormalService.updateBizPmiFormal(bizPmiFormal));
    }

    /**
     * 删除山东制造业PMI
     */
//    @PreAuthorize("@ss.hasPermi('pimFormal:pimFormal:remove')")
//    @Log(title = "山东制造业PMI", businessType = BusinessType.DELETE)
	@DeleteMapping("/{baseIds}")
    public AjaxResult remove(@PathVariable String[] baseIds)
    {
        return toAjax(bizPmiFormalService.deleteBizPmiFormalByBaseIds(baseIds));
    }

    /**
     * <p>
     *     查询APP左上角的日期数据
     * </p>
     * @return 日期的集合
     */
    @GetMapping("/getUniqueDatesFromDatabase")
    public AjaxResult getUniqueDatesFromDatabase(){
        List<String> dateArgs = bizPmiFormalService.getUniqueDatesFromDatabase();
        return AjaxResult.success(dateArgs);
    }
}
